﻿using Microsoft.EntityFrameworkCore;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Domain.Repository;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.Repository
{
    public class EquipmentRepository : RepositoryBase, IEquipmentRepository
    {
        public EquipmentRepository(WmsDbContext dbContext) : base(dbContext)
        {
        }

        public async Task<EquipmentPO?> GetEquipment(string lineCode, string equipmentCode)
        {
            return await dbContext.Set<EquipmentPO>().AsNoTrackingWithIdentityResolution().FirstOrDefaultAsync(entity => entity.LineCode == lineCode && entity.Code == equipmentCode);
        }

        public async Task<List<EquipmentPO>> GetScList(string lineCode, string zoneCode)
        {
            var equipmentStateList = new List<string>()
            {
                "EquipmentState_OK"
            };

            var equipmentUseStateList = new List<string>()
            {
                "EquipmentUseState_Enabled",
                "EquipmentUseState_OnlyInbound"
            };

            return await dbContext.Set<EquipmentPO>().AsNoTrackingWithIdentityResolution()
                .Where(entity => entity.LineCode == lineCode && entity.ZoneCode == zoneCode && equipmentStateList.Contains(entity.StateCode) && equipmentUseStateList.Contains(entity.UseStateCode))
                .ToListAsync();
        }
    }
}
